package com.wjq.demo.xml;

import ch.qos.logback.core.Context;
import ch.qos.logback.core.ContextBase;
import ch.qos.logback.core.joran.action.Action;
import ch.qos.logback.core.joran.spi.ElementSelector;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.util.StatusPrinter;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @author wjq
 * @since 2023-04-11
 */
public class HelloWorld {
    public static void main(String[] args) throws JoranException {
        Map<ElementSelector, Action> ruleMap = new HashMap<>(1);
        // 把"helloWorld"模式和HelloWorldAction关联
        ruleMap.put(new ElementSelector("helloWorld"), new HelloWorldAction());

        SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap);
        // Joran内部需要一个上下文
        Context context = new ContextBase();
        // 设置上下文
        simpleConfigurator.setContext(context);
        simpleConfigurator.doConfigure(Objects.requireNonNull(HelloWorld.class.getResource("/helloworld.xml")));


        StatusPrinter.print(context);
    }
}
